# Maintainer: Kyle Keen <keenerd@gmail.com>
# Contributor: Abhishek Dasgupta <abhidg@gmail.com>
# Contributor: Jason Taylor <jftaylor21@gmail.com>
# Contributor: Luis Henrique <lmello.009@gmail.com>

pkgname=ngspice
pkgver=40
pkgrel=1
pkgdesc='Mixed-level/Mixed-signal circuit simulator based on Spice3f5, Ciber1b1, and Xspice.'
url='http://ngspice.sourceforge.net'
license=('BSD')
arch=('loong64' 'x86_64')
depends=('libxaw' 'libedit' 'gcc-libs')
source=("https://downloads.sourceforge.net/project/$pkgname/ng-spice-rework/$pkgver/$pkgname-$pkgver.tar.gz"
        "https://ngspice.sourceforge.net/docs/ngspice-$pkgver-manual.pdf")
sha256sums=('e303ca7bc0f594e2d6aa84f68785423e6bf0c8dad009bb20be4d5742588e890d'
            '25b640f9f2015cf3df3a2047ed76ccae9fd08bf2b50858f106a6f6e0e7b5f640')

# figure out why libedit is okay, but readline isn't

build() {
  cd $pkgname-$pkgver

  # FS#45230, create so lib
  # shared lib sets flags and modifies headers, needs dedicated pass
  ./configure --prefix=/usr \
              --mandir=/usr/share/man \
              --infodir=/usr/share/info \
              --with-readline=no \
              --enable-xspice \
              --enable-cider \
              --enable-openmp \
              --disable-debug \
              --with-ngshared
  make
  #strip ./src/.libs/libngspice.so.0.0.0

  ./configure --prefix=/usr \
              --mandir=/usr/share/man \
              --infodir=/usr/share/info \
              --with-readline=no \
              --enable-xspice \
              --enable-cider \
              --disable-debug \
              --enable-openmp
  make
  # --enable-oldapps seems broken on v36?
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  install -D -m644 COPYING "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -D -m644  "$srcdir/ngspice-$pkgver-manual.pdf" "$pkgdir/usr/share/doc/$pkgname/manual.pdf"

  install -Dm755 src/.libs/libngspice.so.0.0.7 "$pkgdir/usr/lib/libngspice.so.0.0.7"
  ln -s "libngspice.so.0.0.7" "$pkgdir/usr/lib/libngspice.so.0"
  ln -s "libngspice.so.0.0.7" "$pkgdir/usr/lib/libngspice.so"
  # FS#70563, probably remove on v35
  install -Dm644 ngspice.pc "$pkgdir/usr/lib/pkgconfig/ngspice.pc"
  install -Dm644 src/include/ngspice/sharedspice.h "$pkgdir/usr/include/ngspice/sharedspice.h"
}
